{% extends 'homepage.html' %}
{% block content %}

<script>
jQuery.fn.dataTableExt.oSort['label-asc']  = function(xl,yl) {
  var partsx, partsy;
  partsx = xl.replace(/<.*>(.*)<.*>/g,"$1");
  partsy = yl.replace(/<.*>(.*)<.*>/g,"$1");
  partsx = partsx.split(".");
  partsx = partsy.split(".");
  x = new Array();
  y = new Array();
  var j;
  for (j in partsx) x.push(parseInt(j));
  for (j in partsy) y.push(parseInt(j));
  if(x[0]==y[0]) {
    return ((x[2] < y[2]) ? -1 : ((x[2] > y[2]) ?  1 : 0));
  } else {
    return ((x[0] < y[0]) ? -1 : 1);
  }
};

jQuery.fn.dataTableExt.oSort['label-desc'] = function(xl,yl) {
  var partsx, partsy;
  partsx = xl.replace(/<.*>(.*)<.*>/g,"$1");
  partsy = yl.replace(/<.*>(.*)<.*>/g,"$1");
  partsx = partsx.split(".");
  partsx = partsy.split(".");
  x = new Array();
  y = new Array();
  var j;
  for (j in partsx) x.push(parseInt(j));
  for (j in partsy) y.push(parseInt(j));
  if(x[0]==y[0]) {
    return ((x[2] < y[2]) ? 1 : ((x[2] > y[2]) ?  -1 : 0));
  } else {
    return ((x[0] < y[0]) ? 1 : -1);
  }
};


 $(document).ready(function() {
     $('#fieldTab').dataTable({
       "bFilter": false, 
       "aaSorting": [[0, 'asc']],
        "oLanguage": {
                "oPaginate": {
                        "sPrevious": "",
                        "sNext": "",
                }
        },
       "aoColumns": [
			{ "sType": 'label' },
			null,
			null,
			null,
			null
		],
       "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
       "fnRowCallback": function( row, data, index ){ 
             MathJax.Hub.Queue(['Typeset', MathJax.Hub, row]);
             return row;
         }
     });
 });
</script>



<h2> Further refine search </h2>

<form>
<input type="hidden" name="start" value="{{info.start}}"/>
<table border="0">

<tr>
<td align=left> {{KNOWL('nf.degree', title='degree')}} <td align=left> <input type='text' name='degree' size="3" value="{{info.degree}}"></td>
<td align=left> {{KNOWL('nf.discriminant', title='discriminant')}} range <td align=left> <input type='text' name='discriminant' size=5 value="{{info.discriminant}}"></td>
<td align=left> {{KNOWL('nf.galois_group', title='Galois group')}} <td align=left> <input type='text' name='galois_group' size=3 value="{{info.galois_group}}"></td></tr>
<tr>
<td align=left> {{KNOWL('nf.class_number', title='class number')}} <td align=left> <input type='text' name='class_number' size=3 value="{{info.class_number}}"></td>
<td align=left> {{KNOWL('nf.ideal_class_group', title='class group')}} <td align=left> <input type='text' name='class_group' size=5 value="{{info.class_group}}"></td>
<td align=left> {{KNOWL('nf.unramified_prime', title='unramified primes')}}<td align=left> <input type='text' name='ur_primes' size=3 value="{{info.ur_primes}}"></td>
</tr>

<tr> 
<td align=left><button type='submit' value='refine'>Search again</button></td> 
</tr>
</table>
</form>


<h2> Results: ({{info.report}})</h2>

<table border=1 cellpadding=5 class="ntdata", id="fieldTab"`>
<thead>
<tr>
<th>Label</th>
<th>Polynomial</th>
<th>Discriminant</th>
<th>Galois group</th>
<th>Class group</th>
</tr>
</thead>
<tbody>
{% for field in info.fields: %}
<tr>
<td align='left'><a href="/NumberField/{{field.label}}">{{field.label}}</a></td>
<td>{{info.format_coeffs(field.coefficients)|safe}}</td>
<td>{{field.discriminant}}</td>
<td>{{ info.group_display(field.gal) }}</td>
{% if field.class_group==[] %}
<td> Trivial </td>
{% endif %}
{% if field.class_group!=[] %}
<td>{{field.class_group}}</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>



{% endblock %}
